import { Controller, Get, Inject, Post, Request,Query,Body,Param,Headers } from '@nestjs/common';
import { GirlService } from './girl.service';

@Controller('girl')
export class GirlController {
  constructor(
    @Inject('girl') private girlService:GirlService,
    @Inject('girlArray') private girls:string[],
    @Inject('MyFactory') private myFactory:string[],
  ){}

  @Get('/add')
  addGirl():any{
    return this.girlService.addGirl()
  }

  @Get('/delete/:id')
  delGirl(@Param() params):any{
    let id:number = parseInt(params.id)
    return this.girlService.delGirl(id)
  }

  @Get('/update/:id')
  updateGirl(@Param() params):any{
    let id:number = parseInt(params.id)
    return this.girlService.updateGirl(id)
  }

  @Get()
  getGirl(){
    return this.girlService.getGirl()
  }

  @Get('/findGirlByName/:name')
  findGirlByName(@Param() params):any{
    let name:string = params.name
    return this.girlService.getGirlByName(name)
  }

  @Get('/test')
  test(){
    return this.myFactory
  }

@Get('/corstest')
corsTest():object{
  return {message:'测试跨域请求成功。'}
}








  // GET/POST请求基础语法

  // @Get()
  // getGirls():any{
  //   return this.girlService.getGirls()
  // }
  // Request
  // @Post('/add')
  // addGirl(@Request() req):any{
  //   console.log(req.body);
  //   return this.girlService.addGirls()
  // }

  // Body
  // @Post('/add')
  // addGirl(@Body() body):any{
  //   console.log(body);
  //   return this.girlService.addGirls()
  // }

  // Request
  // @Get('/getGirlById')
  // getGirlById(@Request() req):any{
  //   let id:number = parseInt(req.query.id)
  //   return this.girlService.getGirlById(id)
  // }

  // Query
  // @Get('/getGirlById')
  // getGirlById(@Query() query):any{
  //   let id:number = parseInt(query.id)
  //   return this.girlService.getGirlById(id)
  // }

  // @Get('/findGirlById/:id/:name')
  // findGirlById(@Param() param, @Headers() header):any{
  //   console.log(header);
    
  //   let id:number = parseInt(param.id)
  //   return this.girlService.getGirlById(id)
  // }
}
